const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://taosha_user:apyl8XWP6LSW4JHs@101.35.6.34:27722/taosha";

async function main() {
  const client = await MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
  const db = client.db('taosha');


  let topics = await db.collection('topics')
    .find(
      {author_name: '奇舞精选'}
    )
    .toArray();


  for (let i = 0; i < topics.length; i++) {
    let topic = topics[i];
    // console.log(topic.boards, topic.tags, '--------------');
    if (topic.boards.includes('大厂团队')) {
      topic.boards.splice(topic.boards.indexOf('大厂团队'), 1);
    }
    if (topic.tags.includes('大厂团队')) {
      topic.tags.splice(topic.tags.indexOf('大厂团队'), 1);
    }
    // console.log(topic.boards, topic.tags, '++++++++++++');
    let result = await db.collection('topics').updateOne({_id: topic._id}, {
      $set: {
        boards: topic.boards,
        tags: topic.tags,
      },
    });
    console.log(result.result, i, topics.length);
  }

  client.close();

}

main();
